// hyb_yl/czhuanjiasubpages/pages/longsever/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    argeen: false,
    title:"",
    backgroundColor:"#00c792",
    neworder:[]
  },
  nextpage: function () {
    var that = this
    var sid = that.data.sid
    var key = that.data.key
    var name = that.data.name;
    var argeen = that.data.argeen;
    var zid = that.data.zid
    var server = that.data.key
    var money = that.data.money
    var openid = wx.getStorageSync('openid');
    if(openid == '')
    {
      wx.showModal({
        cancelColor: '提示',
        content:'请先登录',
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
        }
      })
    }else if (!argeen) {
      wx.showModal({
        title: '提示',
        content: "请先订阅并同意" + that.data.detail.titles + "协议",
        success: function (con) {
          if (con.confirm) {
            that.setData({
              argeen: true,
              xieyi: true
            })
          }
        }
      })
    } else {
      if(key != 'yuanchengguahao'){
        
        wx.navigateTo({
          url: '/hyb_yl/userLife/pages/lianmlist/lianmlist?leixing=lvtong&pinyin='+key + '&id='+that.data.detail.id+ '&name='+that.data.name + '&money='+that.data.info.money,
        })
        return false;
      }
      if (that.data.ifzy !== '1') {
        wx.navigateTo({
          url: '/hyb_yl/userLife/pages/lianmlist/lianmlist?long=long&pinyin=' + key,
        })
        return false;
      } else {
        wx.navigateTo({
          url: '/hyb_yl/zhuanjiasubpages/pages/doctor_detail/doctor_detail?inquiry=1&zid=' + zid + '&server=' + server + '&money=' + money
        })
        // wx.navigateTo({
        //   url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=1&zid=' + zid + '&server=' + server + '&money=' + money
        // })
        return false;
      }

    }



  },

  urlpage1: function () {
    console.log(4546000)
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/estimate/estimate?key=' + this.data.key
    })
  },
  // 是否同意协议
  radioChange() {
    this.setData({
      argeen: !this.data.argeen,
      xieyi: true
    })
  },
  closezhe: function () {
    this.setData({
      xieyi: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var sid = options.sid
    if (options.key != undefined) {
      var key = options.key
    } else if(options.key_words != undefined){
      var key = options.key_words
    }else if(options.ser_key != undefined)
    {
      var key = options.ser_key;
    }
    if(key == 'yuanchengguahao')
    {
      that.setData({
        title:'挂号'
      })
    }else{
      that.setData({
        title:options.name,
        key:key
      })
    }
    that.getser_type();
    app.util.request({
      'url': 'entry/wxapp/index.neworder',
      data:{
        type:key
      },
      success: function (res) {
        that.setData({
          neworder: res.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
    var name = options.name
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    if (options.name != undefined) {
      wx.setNavigationBarTitle({
        title: options.name,
      })
    } else if (options.tit != undefined) {
      wx.setNavigationBarTitle({
        title: options.tit,
      })
    }
    app.util.request({
      'url':"entry/wxapp/index.base",
      success:function(res)
      {
        var se = res.data.ztcolor
        that.setData({
          backgroundColor:se
        })
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: se,
        })
      }
    })
    if(options.name != undefined)
    {
      wx.setNavigationBarTitle({
        title: options.name,
      })
    }
    else if(options.tit != undefined)
    {
      wx.setNavigationBarTitle({
        title: options.tit,
      })
    }
    if (options.zid) {
      var zid = options.zid
      that.setData({
        zid: zid
      })
    }
    if (options.ifzy) {
      var ifzy = options.ifzy
      that.setData({
        ifzy: ifzy
      })
    }
    if (options.money) {
      var money = options.money
      that.setData({
        money: money
      })
    }
    that.setData({
      sid: sid,
      key: key,
      name: name,
      bgc: bgc,
    })
    app.util.request({
      'url': 'entry/wxapp/index.detailserones',
      data: {
        ser_key: key
      },
      success: function (res) {
        console.log(res)
        that.setData({
          detail: res.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  getser_type:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/green.ser_type",
      data:{
        keyword:that.data.key,
      },
      success:function(res){
        that.setData({
          info:res.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})